/*
 * Copyright 2010 Michael Nitsche
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.mnit.basis.swt.element.feld.menue;

import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Widget;

import de.mnit.basis.daten.FilterText;
import de.mnit.basis.fehler.Fehler;
import de.mnit.basis.fehler.system.F_Sys_Datei;
import de.mnit.basis.swt.element.feld.A_SWT_Feld;
import de.mnit.basis.swt.grafik.Bild_SWT;
import de.mnit.basis.swt.grafik.S_Bild_SWT;
import de.mnit.basis.swt.grafik.S_SWT_Hat_Bild;
import de.mnit.basis.swt.statisch.TasteSWT;

/**
 * @author Michael Nitsche
 * 14.10.2010	Erstellt
 */
public abstract class A_SWT_MenueFeld<T extends A_SWT_Feld<?,?>> extends A_SWT_Feld<T,MenuItem> {

	private String text;


	public A_SWT_MenueFeld(String text) {
		this.text=text;
	}


	public void sBild(S_SWT_Hat_Bild datei) {
		swt().setImage(datei.gBild().gImage());
	}

	public void sBild(Object datei) throws F_Sys_Datei {
		swt().setImage(Bild_SWT.neu(datei).gImage()); //Vor OS mit: BildX_SWT.neu(datei,16,16)
	}

	/** z.B.: "STRG+A" */
	public void sHotKey(String tasten) {
		int zahl=TasteSWT.textZuZahl(tasten);
		String text=FilterText.bis("\t".toCharArray(),false,swt().getText());
		swt().setText(text+"\t"+TasteSWT.zahlZuText(zahl));
		swt().setAccelerator(zahl);
	}

	public void sAktiv(boolean aktiv) {
		swt().setEnabled(aktiv);
	}

	public S_Bild_SWT gBild() {
		try {
			return Bild_SWT.neu(swt().getImage());
		}
		catch(F_Sys_Datei e) {
			throw Fehler.sonstige.da_Unmoeglich(e);
		}
	}

	// ERZEUGEN

	protected abstract int gTyp();

	protected MenuItem roh(Widget basis, int style) {
		Fehler.objekt.wenn_Null(basis);
		return new MenuItem((Menu)basis,style);
	}

	protected int style3()   { return gTyp(); }

	protected void init3() {
		swt().setText(this.text);
	}

}
